<?php
/**
---------------------------------------
Table tintucphongthuy
---------------------------------------
*/

/**
count rows table tintucphongthuy
*/
function getRowsPhongThuy() {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM tintucphongthuy WHERE del_flg='0'";
	return $con -> getvalueString($sql);
}

/**
get table tintucphongthuy limit
*/
function getPhongThuysLimit($start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select pro_code, title, content_tt, tac_gia, date_create, date_update, isuse, link FROM tintucphongthuy WHERE del_flg='0' ORDER BY date_update DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get table tintucphongthuy
*/
function getPhongThuys() {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('pro_code', 'title', 'content_tt', 'tac_gia', 'date_create', 'date_update', 'link');
	$condetion = array('isuse' => '1', 'del_flg' => '0');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
get table tintucphongthuy by id
*/
function getPhongThuyByID($id) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('pro_code', 'title', 'content_tt', 'content', 'tac_gia', 'date_create', 'date_update', 'isuse', 'link');
	$condetion = array('pro_code' => $id, 'del_flg' => '0');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
insert table tintucphongthuy
*/
function insertPhongThuy($id, $nameProduct, $content_tt, $content, $tac_gia, $image) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('pro_code' => $id, 'title' => $nameProduct, 'link' => $image, 'content_tt' => $content_tt, 'content' => $content, 'tac_gia' => $tac_gia, 'date_create' => time(), 'date_update' => time());
	return $con -> insert($tbl, $fn);
}

/**
display table tintucphongthuy for id
*/
function displayPhongThuy($id, $isuse) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('isuse' => $isuse);
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}
/**
update display list id
*/
function displayPhongThuyList($ids, $isuse) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('isuse' => $isuse);
	$rowid = 'pro_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table tintucphongthuy for list id
*/
function deleteListPhongThuy($ids) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('del_flg' => '1');
	$rowid = 'pro_code';
	return $con -> updatedels($tbl, $fn, $rowid, $ids);
}

/**
delete table tintucphongthuy for id
*/
function deletePhongThuy($id) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('del_flg' => '1');
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}

/**
update Product
*/
function updatePhongThuy($id, $nameProduct, $content_tt, $content, $tac_gia, $image) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('title' => $nameProduct, 'link' => $image, 'content_tt' => $content_tt, 'content' => $content, 'tac_gia' => $tac_gia, 'date_update' => time());
	$conf = array('pro_code' => $id);
	return $con -> update($tbl, $fn, $conf);
}



/**
Hien thi tai index

*/

/**
count rows table tintucphongthuy
*/
function getRowsPhongThuyIndex() {
	$con = new ConnectDB();
	
	$sql = "Select COUNT(*) FROM tintucphongthuy WHERE del_flg='0' AND isuse='1'";
	return $con -> getvalueString($sql);
}

/**
get table tintucphongthuy limit
*/
function getPhongThuysLimitIndex($start, $lenght) {
	$con = new ConnectDB();
	$sql = "Select pro_code, title, content_tt, tac_gia, date_create, date_update, link FROM tintucphongthuy WHERE del_flg='0' AND isuse='1' ORDER BY date_update DESC LIMIT ".$start.",".$lenght;
	return $con -> getvalueString($sql);
}

/**
get table tintucphongthuy by id
*/
function getPhongThuyByIDIndex($id) {
	$con = new ConnectDB();
	$tbl = "tintucphongthuy";
	$fn = array('pro_code', 'title', 'content_tt', 'content', 'tac_gia', 'date_update', 'link');
	$condetion = array('pro_code' => $id, 'del_flg' => '0', 'isuse' => '1');
	return $con -> getvalue($tbl, $fn, $condetion);
}

/**
get products by id type product
*/
function getPhongThuyByTypeTLCIDLienQuan($idpro) {
	$con = new ConnectDB();
	$sql = "Select pro_code, title, content_tt, link, date_update FROM tintucphongthuy WHERE pro_code<>'".$idpro."' AND del_flg='0' AND isuse = '1' ORDER BY date_update DESC LIMIT 0,6";
	return $con -> getvalueString($sql);
}
?>